home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / DOC / YICONS2.DOC < prev   
Text File  |  1993-03-06  |  39KB  |  1,201 lines

  1. yakIcons 2.0 documentation: support modules!
  2.  
  3. The operation of a computer game is a fairly complex thing.  User input,
  4. program output, and disk access must all be juggled by the program.  yakIcons
  5. can help!
  6.  
  7. ---------------------------------------------------------------------------
  8. THE YAKLIB CLASS
  9.  
  10. As you can imagine, an average-to-poor animation sequence length of only five
  11. frames can quickly get out of hand as one eight-direction factor has
  12. 9 positions * five frames/animation = wow, 45 files on disk for one actor!
  13. That's excessive, and that's why you need a yakLib to keep things straight.
  14. If you've ever used disk archiving programs like zip and arj, you've got the
  15. idea behind a yakLib.  No compression is done, however, so graphics can make
  16. yakLibs big fast.
  17.  
  18. yakLibs have a ".yar" extension, for "Yak ARchive" and can be easily manip-
  19. ulated with the "yar.exe" program.
  20.  
  21. #ifndef YAKLIB.H
  22.  
  23. #define YAKLIB.H
  24.  
  25. #include "stddefs.h"
  26.  
  27. #include <fstream.h>
  28.  
  29. class directoryEntry
  30. {
  31. public:
  32.   char filename[15];
  33.   unsigned long index;
  34.   unsigned long size;
  35.   directoryEntry() {filename[0] = '\0'; index = 0; size = 0;};
  36. };
  37.  
  38.  
  39. class yakLib
  40. {
  41.   fstream myDataFile;
  42.   int numberOfEntries;
  43.   long directoryIndex;
  44.   char libFilename[15];
  45. public:
  46.   void open(char * filename);
  47.   yakLib(char * filename);
  48.   void getDirectoryIndex(void);
  49.   directoryEntry getIndex(char * filename);
  50.   void addFile(char *filename);
  51.   unsigned long fileSize(char * filename);
  52.   void extractFile(char *filename);
  53.   int deleteFile(char *filename);
  54.   void listFiles(void);
  55.   byte * loadToMem(char *filename);
  56. };
  57.  
  58. byte * loadDosToMem(char *filename);
  59. #endif
  60.  
  61. class yakLib
  62. {
  63.   fstream myDataFile;   //the actual data file stream.
  64.   int numberOfEntries;  //number of entries in the yakLib
  65.   long directoryIndex;  //position in yakLib file of the directory entries
  66.   char libFilename[15]; //filename of the yakLib
  67. public:
  68.   void open(char * filename);
  69. opens the yakLib, sets directoryIndex!
  70.  
  71.   yakLib(char * filename);
  72. constructor, opens yakLib with the given filename
  73.  
  74.   void getDirectoryIndex(void);
  75. finds directory index of the yakLib
  76.  
  77.   directoryEntry getIndex(char * filename);
  78. gets index of a given file (index = position in yakLib file)
  79.  
  80.   void addFile(char *filename);
  81. adds a file to the yakLib
  82.  
  83.   unsigned long fileSize(char * filename);
  84. returns size of the specified file (in bytes)
  85.  
  86.   void extractFile(char *filename);
  87. extracts a file to disk
  88.  
  89.   int deleteFile(char *filename);
  90. removes a file from the yakLib
  91.  
  92.   void listFiles(void);
  93. lists files in yakLib
  94.  
  95.   byte * loadToMem(char *filename);
  96. allocates memory, loads a file from the lib into memory, and returns a
  97. pointer to the allocated block!
  98.  
  99. };
  100.  
  101.  
  102. ------------------------------------------------------------------------
  103. THE YAKPALETTE CLASS
  104.  
  105. the yakPalette class provides for fast, effective, and easy palette man-
  106. ipulation.  See testi.exe for examples.  Palettes come in .ypl format
  107. or .pal format (loaded with loadDM256).
  108.  
  109.  
  110. #ifndef YAKPAL.H
  111.  
  112. #define YAKPAL.H
  113. #include "stddefs.h"
  114. #include "yaklib.h"
  115. class yakPalette
  116. {
  117. public:
  118.   byte far paletteData[768];
  119.   enum direction {down, up};
  120.   yakPalette(void) {};
  121.   void load(char *filename, yakLib * myYakLib = NULL);
  122.   void loadDM256(char * filename);
  123.   void save(char *filename);
  124.   void get(word startColor = 0, word numColors = 256);
  125.   void put(word startColor = 0, word numColors = 256);
  126.   yakPalette(char * filename, yakLib * myYakLib = NULL)
  127.     {load(filename, myYakLib);};
  128.   void rotate(direction myDirection, word startColor = 0, word numColors = 256);
  129.   void setColor(byte color, byte r, byte g, byte b);
  130.   void fade(char intensity, word startColor = 0, word numColors = 256);
  131. };
  132. #endif
  133.  
  134. public:
  135.   byte far paletteData[768];  //the actual palette data
  136.   enum direction {down, up};  //enumerated type for palette rotation
  137.   yakPalette(void) {};        //default constructor
  138.   void load(char *filename, yakLib * myYakLib = NULL);
  139. loads a .ypl palette into the data area, optionally from yakLib.
  140.  
  141.   void loadDM256(char * filename);
  142. loads a .pal palette into the data area.
  143.  
  144.   void save(char *filename);
  145. saves a .ypl format palette
  146.  
  147.   void get(word startColor = 0, word numColors = 256);
  148. reads palette from DAC to data area
  149.  
  150.   void put(word startColor = 0, word numColors = 256);
  151. puts palette from data area to DAC
  152.  
  153.   yakPalette(char * filename, yakLib * myYakLib = NULL)
  154.     {load(filename, myYakLib);};
  155. constructor which loads palette
  156.  
  157.   void rotate(direction myDirection, word startColor = 0, word numColors = 256);
  158. rotates the given range of colors one color in myDirection.  Put back to screen
  159. to see effect.
  160.  
  161.   void setColor(byte color, byte r, byte g, byte b);
  162. Sets a color in the palette to (r,g,b) values.
  163.  
  164.   void fade(char intensity, word startColor = 0, word numColors = 256);
  165. Reduces or increases intensity of range of colors by a value of intensity.
  166. positive--brighter, negative--darker.
  167. };
  168.  
  169. ---------------------------------------------------------------------------
  170. THE YAKFONT CLASS
  171.  
  172. Fonts are of primary importance in any game, as more than likely text will be
  173. required at some point!
  174.  
  175. #include "stddefs.h"
  176. #include "yakLib.h"
  177. #include "yakwin.h"
  178. #include "xlib.h"
  179. #include "xtext.h"
  180.  
  181. class yakFont
  182. {
  183. public:
  184.   word startChar; //ascii code of first character in font
  185.   byte charHeight; //height of characters
  186.   byte charWidth;  //width of characters
  187.   byte *fontData; //data for characters in font, includes first three items
  188.           //(ie character data starts at fontData[4])
  189.   byte numberOfChars;
  190.   yakFont(int iStartChar, int iCharWidth, int iCharHeight, int numChars)
  191.     {startChar = iStartChar; charWidth = iCharWidth; charHeight = iCharHeight; fontData = new byte[(int)numChars * (int)charHeight + 4];};
  192.   yakFont(void) {startChar = 0; charHeight = charWidth = 0; fontData = NULL; numberOfChars = 0;};
  193.   void load(char * filename, yakLib * myYakLib = NULL);
  194.   yakFont(char * filename, yakLib * myYakLib = NULL) {fontData = NULL; load(filename, myYakLib);};
  195.   void registerMe(void);
  196.   void save(char * filename);
  197.   void use(void);
  198. };
  199.  
  200.  
  201.  
  202. public:
  203.   word startChar; //ascii code of first character in font
  204.   byte charHeight; //height of characters
  205.   byte charWidth;  //width of characters
  206.   byte *fontData; //data for characters in font, includes first three items
  207.           //(ie character data starts at fontData[4])
  208.   byte numberOfChars; //three guesses!
  209.  
  210.   yakFont(int iStartChar, int iCharWidth, int iCharHeight, int numChars)
  211.     {startChar = iStartChar; charWidth = iCharWidth; charHeight = iCharHeight; fontData = new byte[(int)numChars * (int)charHeight + 4];};
  212. constructor.
  213.  
  214.   yakFont(void) {startChar = 0; charHeight = charWidth = 0; fontData = NULL; numberOfChars = 0;};
  215. default constructor
  216.  
  217.   void load(char * filename, yakLib * myYakLib = NULL);
  218. loads font from disk (with yakLib if given)
  219.  
  220.   yakFont(char * filename, yakLib * myYakLib = NULL) {fontData = NULL; load(filename, myYakLib);};
  221. loading constructor.
  222.  
  223.   void registerMe(void);
  224. registers font with xlib.
  225.  
  226.   void save(char * filename);
  227. saves font to disk
  228.  
  229.   void use(void);
  230. registers then enables the font.
  231.  
  232. look at yfedit.cpp for examples!
  233.  
  234. ------------------------------------------------------------------------
  235. THE YAKWINDOWS CLASSES
  236.  
  237. In windows fashion, the yakWindowPane is a rectangular area of screen
  238. which can save or restore itself.  Useful for cleaning up sprites, dialog
  239. boxes, or anything!
  240.  
  241. //contains header information for the yakWindows classes; at this
  242. //stage, just yakWindowPane
  243. #ifndef YAKWIN.H
  244. #define YAKWIN.H
  245.  
  246. #include "stddefs.h"
  247. #include "xlib.h"
  248. #include <stdlib.h>
  249.  
  250. class yakWindowPane
  251. {
  252. public:
  253.   word x, y, width, bWidth, height, myOffset;  //bwidth is width in nibbles
  254.   far byte * myGraphicData;
  255.   yakWindowPane(void) {x = y = bWidth = height = myOffset = 0; myGraphicData = NULL;};
  256.   yakWindowPane(word x1, word y1, word x2, word y2);
  257.   ~yakWindowPane() {delete myGraphicData;};
  258.   void reSave(word x1, word y1, word x2, word y2, word offset);
  259.   void save(word x1, word y1, word offset);
  260.   void save(void);
  261.   void restore(word offset);
  262.   void restore(void);
  263. };
  264.  
  265. class yakWindow : public yakWindowPane
  266. {
  267. public:
  268.   static yakWindow * killPointer;
  269.   enum flags {isSizeable = 0x01, isDraggable = 0x02, isCloseable = 0x04, isTemporary = 0x08};
  270.   word myNumber;
  271.   flags myFlags;
  272.   byte titleBarColor, textColor, boxColor;
  273.   char title[80];
  274.   yakWindow * nextWindow, * prevWindow;
  275.   static yakWindow * bottomWindow, * topWindow;
  276.   static yakWindow * activeWindow;
  277.   yakWindow(int x1, int y1, int x2, int y2);
  278.   void open(void);
  279.   void close(void);
  280.   void showActivated(void);
  281.   void showActivated(word offset);
  282.   void showDeActivated(void);
  283.   void showDeActivated(word offset);
  284.   virtual void draw(word offset); //redefine this one!
  285.   virtual void draw(void);
  286.   void shuffleToTop(void);
  287.   virtual word interpretMouseClick(void);
  288.   virtual word interpretKeyStroke(char myChar);
  289.   void drag(void);
  290.   void size(void);
  291.   virtual int isSelected(void);
  292.   virtual int isDragSelected(void);
  293.   virtual int isSizeSelected(void);
  294.   virtual int isCloseSelected(void);
  295.   static void drawAll(void);
  296.   static void selectToTop(void);
  297.   static word advance(void);
  298. };
  299.  
  300. #endif
  301. class yakWindowPane
  302. {
  303. public:
  304.   word x, y, width, bWidth, height, myOffset;  //bwidth is width in nibbles (groups
  305.                     //of 4 pixels
  306.   far byte * myGraphicData;    //where video memory is copied to
  307.  
  308.   yakWindowPane(void) {x = y = bWidth = height = myOffset = 0; myGraphicData = NULL;};
  309. default const.
  310.  
  311.   yakWindowPane(word x1, word y1, word x2, word y2);
  312. constructor which takes coords of the top left and bottom right corners
  313.  
  314.   ~yakWindowPane() {delete myGraphicData;};
  315. default destructor; frees up memory used by the windowpane.
  316.  
  317.   void reSave(word x1, word y1, word x2, word y2, word offset);
  318. saves screen memory into myGraphicData, reallocating if necessary
  319.  
  320.   void save(word x1, word y1, word offset);
  321. saves screen memory into myGraphicData using current bwidth and height
  322.  
  323.   void save(void);
  324. saves screen memory into myGraphicData using current position, bwidth,
  325. height, and offset.
  326.  
  327.   void restore(word offset);
  328. restores screen memory from myGraphicData using current position, bwidth, and
  329. height
  330.  
  331.   void restore(void);
  332. like above but uses current offset.
  333. };
  334.  
  335. class yakWindow : public yakWindowPane
  336. {
  337. public:
  338.   static yakWindow * killPointer;
  339. holds the address of the next window to be closed when the manager is
  340. called.
  341.  
  342.   enum flags {isSizeable = 0x01, isDraggable = 0x02, isCloseable = 0x04, isTemporary = 0x08};
  343. These flags contain the different options for a window.  Is it sizeable,
  344. draggable, closeable, or temporary (deleted when closed)?
  345.  
  346.   word myNumber;
  347. Window number.
  348.  
  349.   flags myFlags;
  350. this window's flags.
  351.  
  352.   byte titleBarColor, textColor, boxColor;
  353. used for drawing.
  354.  
  355.   char title[80];
  356. text displayed at top of this window.
  357.  
  358.   yakWindow * nextWindow, * prevWindow;
  359. pointers to the surrounding windows in the stack.
  360.  
  361.   static yakWindow * bottomWindow, * topWindow;
  362. Addresses of the top and bottom windows.
  363.  
  364.   static yakWindow * activeWindow;
  365. Window to recieve mouse signals and keyboard inputs.
  366.  
  367.   yakWindow(int x1, int y1, int x2, int y2);
  368. Default constructor.
  369.  
  370.   void open(void);
  371. opens the window on screen.
  372.  
  373.   void close(void);
  374. restores the background and closes the window.
  375.  
  376.   void showActivated(void);
  377.   void showActivated(word offset);
  378. Displays the window as "activated"
  379.  
  380.   void showDeActivated(void);
  381.   void showDeActivated(word offset);
  382. displays the window as "deactivated".
  383.  
  384.   virtual void draw(word offset); //redefine this one!
  385.   virtual void draw(void);
  386. The actual code to draw the window.  Redefine in derived classes for endless
  387. versatility.
  388.  
  389.   void shuffleToTop(void);
  390. Moves the window to the top of the stack.
  391.  
  392.   virtual word interpretMouseClick(void);
  393. Tells the window how to interpret a mouse click.
  394.  
  395.   virtual word interpretKeyStroke(char myChar);
  396. Tells the window how to interpret a key stroke.
  397.  
  398.   void drag(void);
  399. Drags the window to a new position.
  400.  
  401.   void size(void);
  402. Stretches the window to a new size.
  403.  
  404.   virtual int isSelected(void);
  405. Checks to see if the window is selected.
  406.  
  407.   virtual int isDragSelected(void);
  408. ...dragged,
  409.  
  410.   virtual int isSizeSelected(void);
  411. ...resizing,
  412.  
  413.   virtual int isCloseSelected(void);
  414. ...or closing.
  415.  
  416.   static void drawAll(void);
  417. Draws all windows from bottom to top of the window stack.  For restoring the
  418. screen.
  419.  
  420.   static void selectToTop(void);
  421. Selects the mouse-selected window to the top of the stack.
  422.  
  423.   static word advance(void);
  424. Advances the window stack.  If any mouse events are waiting, advance() sends
  425. them to the appropriate window.  Same with keyboard.
  426. };
  427.  
  428. ------------------------------------------------------------------------
  429. THE YAKSCROLLER CLASS
  430.  
  431. Of paramount importance to information oriented games is the dialog box,
  432. where the program can spit out text which the user scrolls through as he
  433. wishes.  The yakScroller does this, then cleans up the screen after itself
  434. like a window!  See testi.cpp for an example.  YakScrollers are wordwrapped,
  435. so don't worry about that.
  436.  
  437. #include "stddefs.h"
  438. #include "yakLib.h"
  439. #include "yakwin.h"
  440. #include "xlib.h"
  441. #include "xtext.h"
  442.  
  443. class yakScroller : public yakWindow
  444. {
  445. public:
  446.   int position; //position is the line # at top.
  447.   enum direction {up, down};
  448.   char * myText;
  449.   yakScroller(word x1, word y1, word x2, word y2, char * imyText, int iposition = 0) :
  450.     yakWindow(x1, y1, x2, y2)
  451.     {myText = imyText; position = iposition;};
  452.   ~yakScroller() {delete myText;};
  453.   virtual void draw(word offset = VisiblePageOffs);
  454.   virtual word interpretKeyStroke(char myChar);
  455.   virtual word interpretMouseClick(void);
  456.   char * getLine(word lineNumber);
  457.   int lineLength(word lineNumber);
  458.   void drawLine(int lineNumber, int x, int y, word offset);
  459.   void activate(int x, int y, word offset = VisiblePageOffs);
  460.   void drawText(int lineNumber, int ix, int iy, word offset = VisiblePageOffs);
  461.   void drawText(int lineNumber, word offset = VisiblePageOffs);
  462.   void drawText(word offset = VisiblePageOffs);
  463.   void newText(byte * theNewText);
  464.   void activate(int x1, int y1, int x2, int y2, word offset, char * theNewText);
  465.   void pageMove(direction pageDirection, word offset = VisiblePageOffs);
  466.   void lineMove(direction lineDirection, word offset = VisiblePageOffs);
  467. };
  468. {
  469. public:
  470.   int position; //position is the line # at top.
  471.   enum direction {up, down}; //direction type for scrolling
  472.   char * myText; //text shown in the box
  473.  
  474.   yakScroller(word x1, word y1, word x2, word y2, char * imyText, byte iBorderColor = 10, byte iBoxColor = 0, byte itextColor = 15, int iposition = 0) :
  475.     yakWindowPane(x1, y1, x2, y2)
  476.     {width = x2-x1; myText = imyText; borderColor = iBorderColor; boxColor = iBoxColor; textColor = itextColor; position = iposition;};
  477. constructor for yakScroller using diagonal corners, etc.
  478.  
  479.   ~yakScroller() {delete myText;};
  480. default destructor.
  481.  
  482.   void draw(word offset = VisiblePageOffs);
  483. draws yakScroller using current coords
  484.  
  485.   virtual word interpretKeyStroke(char myChar);
  486.   virtual word interpretMouseClick(void);
  487. Tells the yakScroller how to interpret clicks and keystrokes.  The top and
  488. bottom bars of the yakscroller scroll the text in the appropriate direction
  489. if clicked on.  Arrow keys and pgUp/Dn also work.
  490.  
  491.   char * getLine(word lineNumber);
  492. gets position in memory of the line <linenumber>, correcting for wordwrap
  493.  
  494.   int lineLength(word lineNumber);
  495. returns length of a given line number.
  496.  
  497.   void drawLine(int lineNumber, int x, int y, word offset);
  498. draws a line of text
  499.  
  500.   void activate(int x, int y, word offset = VisiblePageOffs);
  501. activates scroller at given position and offset, allowing the user to
  502. scroll text with the up/down arrows and pageup/pagedown.
  503.  
  504.   void drawText(int lineNumber, int ix, int iy, word offset = VisiblePageOffs);
  505. fills box with text starting with lineNumber at given coords.
  506.  
  507.   void drawText(int lineNumber, word offset = VisiblePageOffs);
  508. fills box with text starting at lineNumber at current coords.
  509.  
  510.   void drawText(word offset = VisiblePageOffs);
  511. fills box with text starting at <position> at current coords.
  512.  
  513.   void newText(byte * theNewText);
  514. frees memory at myText and reassigns it.  This could be hazardous if you're
  515. not careful.
  516.  
  517.   void activate(int x1, int y1, int x2, int y2, word offset, char * theNewText);
  518. activates using diagonal box coordinates, given offset, and new text.
  519.  
  520.   void pageMove(direction pageDirection, word offset = VisiblePageOffs);
  521. scrolls display one page in pageDirection.
  522.  
  523.   void lineMove(direction lineDirection, word offset = VisiblePageOffs);
  524. scrolls display one line in lineDirection.
  525. };
  526.  
  527. -------------------------------------------------------------------------
  528. THE YAKSAMPLE CLASS
  529.  
  530. I haven't toyed too much with this, but I've heard it work!  Sampled sounds
  531. are important for games, and the Soundblaster is a good way to implement
  532. them.  To make this easier, try the yakSample class!  See the soundtst.cpp
  533. program for example!
  534.  
  535. #ifndef YAKSOUND.H
  536.  
  537. #define YAKSOUND.H
  538.  
  539. #include <dos.h>
  540. #include "yaklib.h"
  541.  
  542. class yakSample
  543. {
  544. public:
  545.   byte * sampleData;
  546.   unsigned long sampleLength;
  547.   void play(word sampleRate = 11000, word stereo = 1, word voice = 1, unsigned long length = 0);
  548.   yakSample(void) {sampleData = NULL;};
  549.   yakSample(char * filename) {sampleData = NULL; load(filename);};
  550.   byte * load(char * filename);
  551. };
  552.  
  553. class yakVoc
  554. {
  555. public:
  556.   byte * sampleData;
  557.   void load(char * filename, yakLib * myYakLib = NULL);
  558.   void play(void);
  559. };
  560.  
  561. void CTLoad(void);
  562. int CTGetVersion(void);
  563. void CTSetIOAddr(int base);
  564. void CTSetIRQ(int irq);
  565. int CTInitialize(void);
  566. void CTUninstall(void);
  567. void CTSpeakerOn(void);
  568. void CTSpeakerOff(void);
  569. void CTSetStatusWord(word * address);
  570. void CTOutputVoice(char * buffer);
  571. void CTInputVoice(int sampleRate, char* buffer, long length);
  572. void CTStopVoiceProcess(void);
  573. int CTPauseOutputVoice(void);
  574. int CTContinueOutputVoice(void);
  575.  
  576.  
  577. #endif
  578.  
  579. {
  580. public:
  581.   byte * sampleData;  //data in memory of sound sample
  582.   unsigned long sampleLength; //three guesses
  583.  
  584.   void play(word sampleRate = 11000, word stereo = 1, word voice = 1, unsigned long length = 0);
  585. plays this sample using DMA channels
  586.  
  587.   yakSample(void) {sampleData = NULL;};
  588. def. const.
  589.  
  590.   yakSample(char * filename) {sampleData = NULL; load(filename);};
  591. const which loads sample.
  592.  
  593.   byte * load(char * filename);
  594. loads sample from disk.  Does not implement yakLib, but this is easy to
  595. do (ie myYakSample.sampleData = myYakLib.loadToMem("spam.sam");)
  596. };
  597.  
  598. class yakVoc
  599. {
  600. public:
  601.   byte * sampleData;
  602. Sound data
  603.  
  604.   void load(char * filename, yakLib * myYakLib = NULL);
  605. Loads a .voc file from disk
  606.  
  607.   void play(void);
  608. plays the voc file.
  609.  
  610. };
  611.  
  612. void CTLoad(void);
  613. int CTGetVersion(void);
  614. void CTSetIOAddr(int base);
  615. void CTSetIRQ(int irq);
  616. int CTInitialize(void);
  617. void CTUninstall(void);
  618. void CTSpeakerOn(void);
  619. void CTSpeakerOff(void);
  620. void CTSetStatusWord(word * address);
  621. void CTOutputVoice(char * buffer);
  622. void CTInputVoice(int sampleRate, char* buffer, long length);
  623. void CTStopVoiceProcess(void);
  624. int CTPauseOutputVoice(void);
  625. int CTContinueOutputVoice(void);
  626.  
  627. These are all from the Soundblaster Freedom Project.  They manipulate the
  628. CT-VOICE.DRV driver for the soundblaster.  Documentation is sketchy as of
  629. now.  Look at driver.cpp for some examples of use.
  630.  
  631. --------------------------------------------------------------------------
  632. THE YAKSTICK CLASS
  633.  
  634. The joystick is possibly the most popular game input device.  No gamer should
  635. be without a joystick object!  See testi.cpp for an example
  636.  
  637. #include "stddefs.h"
  638. #ifndef YAKSTICK.H
  639. #define YAKSTICK.H
  640.  
  641. extern int jsense; //sensitivity of stick?
  642. extern int jrange; //range of output values?  Play with these!
  643.  
  644. class yakStick  //joystick class object!
  645. {
  646. public:
  647.   byte stickNumber;
  648.   int x, y;
  649.   byte button1, button2;
  650.   yakStick(byte number) {stickNumber = number; x=y=0; button1=button2=0; jsense = 10; jrange = 200;};
  651.   int read(void);
  652.   int readX(void);
  653.   int readY(void);
  654.   byte readButton1(void);
  655.   byte readButton2(void);
  656. };
  657. #endif
  658.  
  659. {
  660. public:
  661.   byte stickNumber; //id number of joystick
  662.   int x, y;        //x and y of stick position
  663.   byte button1, button2; //0 if off, >0 if on
  664.  
  665.   yakStick(byte number) {stickNumber = number; x=y=0; button1=button2=0; jsense = 10; jrange = 200;};
  666. creates a yakStick object with ID <number>
  667.  
  668.   int read(void);
  669. reads values into x, y, and buttons.
  670.  
  671.   int readX(void);
  672. reads joystick and returns x
  673.  
  674.   int readY(void);
  675. reads joystick and returns y
  676.  
  677.   byte readButton1(void);
  678. reads joystick and returns button1
  679.  
  680.   byte readButton2(void);
  681. reads joystick and returns button2
  682.  
  683. };
  684.  
  685.  
  686. yakstick.cpp uses jstcka.asm (or something like that).  Be sure it's compiled.
  687.  
  688. yakstick.cpp also defines "extern yakStick joyStick1, joyStick2" for use in
  689. your programs, ie you shouldn't ever have to declare an instance of yakStick.
  690.  
  691. ---------------------------------------------------------------------------
  692. THE YAKMOUSE CLASS
  693.  
  694. If the joystick is the preferred input device of action games, the mouse is
  695. the clear winner with everything else.  EVERYTHING seems to use mice these
  696. days, whether we like it or not, and mouse programming is a messy, interrupt-
  697. oriented process... until now.  See yedit.cpp for examples!
  698.  
  699. #ifndef YAKMOUSE.H
  700.  
  701. #define YAKMOUSE.H
  702.  
  703. #include "icon.h"
  704.  
  705. class yakMouse
  706. {
  707. public:
  708.   enum buttonType {noButtons = 0, leftButton = 0x01, rightButton = 0x02, reset = 0xff,
  709.            eitherButton = 0x03};
  710.   void init(void);
  711.   void remove(void);
  712.   void show(void);
  713.   void hide(void);
  714.   void beStandardMouse(void);
  715.   void setImage(char * mouseDef, int color);
  716.   word x(void);
  717.   word y(void);
  718. //  word numberOfButtons(void);
  719.   void display(int x, int y, int topclip, int botclip, word offset);
  720.   word buttonStatus(void);
  721.   byte isPressed(buttonType myButtons);
  722.   byte isClicked(buttonType myButtons);
  723.   byte isInBox(int x1, int y1, int x2, int y2);
  724. };
  725.  
  726. #endif
  727.  
  728. class yakMouse
  729. {
  730. public:
  731.   enum buttonType {noButtons = 0, leftButton = 0x01, rightButton = 0x02, reset = 0xff,
  732.            eitherButton = 0x03}; //mask for isPressed, isClicked
  733.  
  734.   void init(void);
  735. initializes mouse driver.  Do this before anything else.
  736.  
  737.   void remove(void);
  738. deinitializes mouse driver.  A good idea before leaving the program!
  739.  
  740.   void show(void);
  741. Shows mouse at current position.
  742.  
  743.   void hide(void);
  744. Hides mouse.
  745.  
  746.   void beStandardMouse(void);
  747. Sets mouse to my standard mouse.  The mouse has a "notch" in it for a reason:
  748. to check the color of the pixel "under" the mouse, it has to be transparent;
  749. otherwise x_get_pix says "yep, it's white all right."
  750.  
  751.   void setImage(char * mouseDef, int color);
  752. Sets image of mouse to mouseDef.  See formats.doc for this format
  753.  
  754.   word x(void);
  755. reads mouse; returns x coord
  756.  
  757.   word y(void);
  758. reads mouse; returns y coord
  759.  
  760. //  word numberOfButtons(void); removed since xlib04 didn't support it.
  761.  
  762.   void display(int x, int y, int topclip, int botclip, word offset);
  763. draws mouse cursor at given position.  A must for page-flipping, which confuses
  764. herr rodent.
  765.  
  766.   word buttonStatus(void);
  767. returns status of the button variable.
  768.  
  769.   byte isPressed(buttonType myButtons);
  770. returns 0 if mask does not apply, >0 if it does.  Use like this:
  771. if (isPressed(yakMouse::leftButton)).  Returns if the button is currently
  772. pressed.
  773.  
  774.   byte isClicked(buttonType myButtons);
  775. Checks button status.  If the status has changed since last check and the
  776. button is down, returns nonzero value.  Good for toggle switches (see gadgets!)
  777.  
  778.   byte isInBox(int x1, int y1, int x2, int y2);
  779. returns 1 if the mouse cursor is in the specified rectangle on screen.  Useful
  780. for detecting clicks on objects.
  781. };
  782.  
  783.  
  784. Note!  The yakMouse.cpp already has an "extern yakMouse mouse" defined; you
  785. shouldn't have to define your own mouse!
  786. -----------------------------------------------------------------------------
  787. THE YAKKEYBOARD CLASS
  788.  
  789. The problem with keyboard input is that for the most part it's hard to
  790. decide what keys are being pressed, especially if two or more are being
  791. pressed in combination.  The yakKeyboard class takes care of this for you.
  792.  
  793. #ifndef YAKKEYS.H
  794.  
  795. #include "stddefs.h"
  796. #define YAKKEYS.H
  797. //header file for yakKeyboard; adapted from STK code by Jari Karjala
  798.  
  799. class yakKeyboard
  800. {
  801. public:
  802.   enum keyLabel {escape = 1, num1, num2, num3, num4, num5, num6, num7,
  803.                  num8, num9, num0, tab=15, charQ, charW, charE, charR,
  804.                  charT, charY, charU, charI, charO, charP, charA=30,
  805.                  charS, charD, charF, charG, charH, charJ, charK, charL,
  806.                  charZ=44, charX, charC, charV, charB, charN, charM,
  807.                  keyComma, keyDot, spaceBar=57, upArrow = 72, downArrow=80,
  808.                  leftArrow = 75, rightArrow = 77};
  809.   static char keys[128];
  810.   static char * bufferHead, bufferTail;
  811.   static void interrupt (*oldHandler)(...);
  812.   static void interrupt newHandler(...);
  813.   static void install(void);
  814.   static void remove(void);
  815. };
  816.  
  817. #ifndef YAKKEYSUNIT
  818. extern yakKeyboard keyboard;
  819. #endif
  820. #endif
  821.  
  822. class yakKeyboard
  823. {
  824. public:
  825.   enum keyLabel {escape = 1, num1, num2, num3, num4, num5, num6, num7,
  826.                  num8, num9, num0, tab=15, charQ, charW, charE, charR,
  827.                  charT, charY, charU, charI, charO, charP, charA=30,
  828.                  charS, charD, charF, charG, charH, charJ, charK, charL,
  829.                  charZ=44, charX, charC, charV, charB, charN, charM,
  830.                  keyComma, keyDot, spaceBar=57, upArrow = 72, downArrow=80,
  831.                  leftArrow = 75, rightArrow = 77};
  832. The different keys available.
  833.  
  834.   static char keys[128];
  835. The keyboard "buffer"-- if keys[yakKeyboard::charQ] != 0, the "q" key is
  836. being pressed.
  837.  
  838.   static char * bufferHead, bufferTail;
  839. Head and tail of the keyboard buffer.
  840.  
  841.   static void interrupt (*oldHandler)(...);
  842.   static void interrupt newHandler(...);
  843. The old and new handlers for the keyboard.
  844.  
  845.   static void install(void);
  846. Installs new handler...
  847.  
  848.   static void remove(void);
  849. ...and removes it.
  850. };
  851.  
  852. -----------------------------------------------------------------------------
  853. THE GADGET CLASS HIERARCHY
  854.  
  855. I worked long and hard on this.  Lots of packages claim they have mouse support
  856. while just doing what the simple yakMouse class does.  I do them better!  The
  857. gadget hierarchy is an object-oriented hierarchy of four types of gadgets:
  858. buttons (return a given value when you click on them), switches (return their
  859. current position, which changes when you click on them), sliders (which
  860. are like continuously variable switches), and labels (which are just bits of
  861. text that work like buttons).  Used with a gadgetList, you can have a bank
  862. of buttons or switches that are automatically updated with little or no effort
  863. from the programmer.  See the demo program for code examples.
  864. #ifndef GADGETS.H
  865.  
  866. #define GADGETS.H
  867.  
  868. #include "animicon.h"
  869. #include "yakmouse.h"
  870. #include "xlib.h"
  871.  
  872. #define HELP_MASK 4096
  873.  
  874. class gadget : public animicon
  875. {
  876. public:
  877.   enum flagType {normal = 0, touchPad = 1};
  878.   enum gadgetType {buttonType = 1, pSwitchType = 2, sliderType = 3};
  879.   virtual byte isSelected(void);
  880.   word x, y;
  881.   word relX, relY; //used by gadgetManager
  882.   char commandChar;
  883.   flagType flags;
  884.   gadgetType type;
  885.   gadget(char commandChar, char * filename, icon::flagType aflags = icon::normal, yakLib * myYakLib = NULL, gadget::flagType iflags = gadget::normal, int ix = 0, int iy = 0);
  886.   gadget(char icommandChar, animiconNode * thisFrame, gadget::flagType iflags = gadget::normal, int ix = 0, int iy=0);
  887.   gadget(void) : animicon() {x = y = 0; commandChar = 0; flags = normal;};
  888.   virtual void draw(int ix, int iy, word offset) {x=ix; y=iy; animicon::draw(x, y, offset);};
  889.   virtual void draw(word offset = VisiblePageOffs) {draw(x, y, offset);};
  890.   virtual int activate(void) = 0;
  891.   virtual int status(void) = 0;
  892. };
  893.  
  894. class button : public gadget
  895. {
  896. public:
  897.   int returnValue;
  898.   button(int ix, int iy, char commandChar, int returnValue, char * filename, icon::flagType flags = icon::normal, yakLib * myYakLib = NULL, gadget::flagType iflags = gadget::normal);
  899.   virtual int activate(void);
  900.   virtual int status(void);
  901. };
  902.  
  903. class label : public button
  904. {
  905. public:
  906.   char * myText;
  907.   byte fgColor, bgColor;
  908.   label(int ix, int iy, char commandChar, int returnValue, char * text, byte ifgColor = 15, byte ibgColor = 0, gadget::flagType iflags = gadget::normal);
  909.   virtual void draw(int ix, int iy, word offset);
  910.   virtual byte isSelected(void);
  911. };
  912.  
  913. class pSwitch : public gadget
  914. {
  915. public:
  916.   int position;
  917.   pSwitch(int ix, int iy, char commandChar, char * filename, icon::flagType flags = icon::normal, yakLib * myYakLib = NULL, gadget::flagType iflags = gadget::normal);
  918.   virtual int activate(void);
  919.   virtual int status(void);
  920. };
  921.  
  922. class slider : public gadget
  923. {
  924. public:
  925.   int position, width, height;
  926.   int minimumValue, maximumValue;
  927.   byte barColor, borderColor, indicatorColor;
  928.   slider(int ix, int iy, int iwidth, int iheight, int minimumValue, int maximumValue, byte barColor = 0, byte borderColor = 10, byte indicatorColor = 25);
  929.   slider() : gadget() {position = width = height = minimumValue = maximumValue = 0; position = width = height = 0;};
  930.   virtual void draw(word offset = VisiblePageOffs);
  931.   virtual void draw(int x, int y, word offset);
  932.   virtual int activate(void);
  933.   virtual int status(void);
  934. };
  935.  
  936. //Node definitions Follow------------------------------------------>
  937.  
  938. class gadgetNode
  939. {
  940. public:
  941.   gadgetNode * nextGadget;
  942.   gadgetNode * prevGadget;
  943.   gadget * thisGadget;
  944.   gadgetNode(gadget * newGadget, gadgetNode * newNextGadget) {nextGadget = newNextGadget; thisGadget = newGadget, prevGadget = NULL;};
  945. };
  946.  
  947. //list definitions follow----------------------------------------->
  948.  
  949. class gadgetList
  950. {
  951. public:
  952.   gadgetNode * firstGadget;
  953.   gadgetNode * lastGadget;
  954.   virtual int status(void);
  955.   gadgetList() {firstGadget = lastGadget = NULL;};
  956.   void draw(int x, int y, word offset = VisiblePageOffs);
  957.   void draw(word offset = VisiblePageOffs);
  958.   void add(gadgetNode * theNewGadget);
  959. };
  960. #endif
  961.  
  962. THE GADGET CLASS
  963.  
  964. #define HELP_MASK 4096 -- optionally, you can use the help mask to return
  965. (4096 LOGICAL-OR returnValue) for buttons to use as a "help" feature.  Not
  966. implemented fully.
  967.  
  968. class gadget : public animicon
  969. {
  970. public:
  971.   enum flagType {normal = 0, touchPad = 1};
  972. a normal icon is activated by clicking on it.  A touchPad is activated when-
  973. ever the mouse is on it and the cursor is down.  There's a difference!  Look
  974. at the grumjug switch in ymsedemo.cpp; it's a touchpad, while the toggle is
  975. a normal.
  976.  
  977.   enum gadgetType {buttonType = 1, pSwitchType = 2, sliderType = 3};
  978. used to see what kind of a gadget we have.  Buttons return values when
  979. activated; all others must be individually checked.
  980.  
  981.   virtual byte isSelected(void);
  982. Is the icon selected?  Checks to see if the mouse is on the icon, if the
  983. pixel under the cursor really belongs to the icon (stacked icons, like piles
  984. of objects on a map?), checks to see if the gadget's commandChar was pressed,
  985. and returns 1 if the gadget was selected.
  986.  
  987.   word x, y;
  988. position of the gadget
  989.  
  990.   word relX, relY;
  991. used by gadgetManager; relative position of the gadget in the gadgetManager.
  992.  
  993.   char commandChar;
  994. when pressed, this character activates the gadget.
  995.  
  996.   flagType flags;
  997. normal or touchpad?
  998.  
  999.   gadgetType type;
  1000. What kind of gadget?
  1001.  
  1002.   gadget(char commandChar, char * filename, icon::flagType aflags = icon::normal, yakLib * myYakLib = NULL, gadget::flagType iflags = gadget::normal, int ix = 0, int iy = 0);
  1003. Mondo constructor.  Initializes commandChar, loads the animicon from filename,
  1004. sets flags, sets position.
  1005.  
  1006.   gadget(char icommandChar, animiconNode * thisFrame, gadget::flagType iflags = gadget::normal, int ix = 0, int iy=0);
  1007. Another constructor; adds from a pre-made animiconNode instead of a file.
  1008.  
  1009.   gadget(void) : animicon() {x = y = 0; commandChar = 0; flags = normal;};
  1010. def. const.
  1011.  
  1012.   virtual void draw(int ix, int iy, word offset) {x=ix; y=iy; animicon::draw(x, y, offset);};
  1013. draws gadget at given position.
  1014.  
  1015.   virtual void draw(word offset = VisiblePageOffs) {draw(x, y, offset);};
  1016. draws gadget at current position.
  1017.  
  1018.   virtual int activate(void) = 0;
  1019. activates the icon (flips the switch, slides the slider, whatever)
  1020.  
  1021.   virtual int status(void) = 0;
  1022. activates the icon if applicable and returns its status.
  1023. };
  1024.  
  1025. THE BUTTON CLASS
  1026. Buttons, when pressed, return their return value.  By knowing what these are,
  1027. programs can act on a button's press.  Uses one frame of animation.
  1028. class button : public gadget
  1029. {
  1030. public:
  1031.   int returnValue;
  1032. what value this will return when activated.
  1033.  
  1034.   button(int ix, int iy, char commandChar, int returnValue, char * filename, icon::flagType flags = icon::normal, yakLib * myYakLib = NULL, gadget::flagType iflags = gadget::normal);
  1035. mondo constructor.
  1036.  
  1037.   virtual int activate(void);
  1038.   virtual int status(void);
  1039. };
  1040.  
  1041. THE LABEL CLASS
  1042. The label class acts just like a button.  However, they display a segment
  1043. of text instead of an icon.
  1044. class label : public button
  1045. {
  1046. public:
  1047.   char * myText;
  1048. text to display
  1049.  
  1050.   byte fgColor, bgColor;
  1051. Foreground and background color of the text.
  1052.  
  1053.   label(int ix, int iy, char commandChar, int returnValue, char * text, byte ifgColor = 15, byte ibgColor = 0, gadget::flagType iflags = gadget::normal);
  1054. Constructor.
  1055.  
  1056.   virtual void draw(int ix, int iy, word offset);
  1057. Self-explanatory.
  1058.  
  1059.   virtual byte isSelected(void);
  1060. Self-explanatory.
  1061. };
  1062.  
  1063.  
  1064. THE SWITCH CLASS
  1065. Switches, when pressed, advance to their next position.  They have as many
  1066. positions possible as they have frames of animation, ie an animation with
  1067. two frames (togg.yak and togg2.yak) has two positions.
  1068. class pSwitch : public gadget
  1069. {
  1070. public:
  1071.   int position;
  1072. current position of switch
  1073.  
  1074.   pSwitch(int ix, int iy, char commandChar, char * filename, icon::flagType flags = icon::normal, yakLib * myYakLib = NULL, gadget::flagType iflags = gadget::normal);
  1075. mondo constructor
  1076.  
  1077.   virtual int activate(void);
  1078.   virtual int status(void);
  1079. status() returns the position of the switch.
  1080. };
  1081.  
  1082. THE SLIDER CLASS
  1083. You've seen sliders before.  They have a low value, a high value, and a current
  1084. position and look like a bar graph.  If you never check to see if they're
  1085. selected, they make swell bar graphs for fuel, hit points, or whatever as
  1086. well!  A very useful object!
  1087.  
  1088. class slider : public gadget
  1089. {
  1090. public:
  1091.   int position, width, height;  //position:position of slider.  width and
  1092.                 //height are the dimensions of the object
  1093.   int minimumValue, maximumValue; //min and max of the slider
  1094.   byte barColor, borderColor, indicatorColor; //three guesses.
  1095.  
  1096.   slider(int ix, int iy, int iwidth, int iheight, int minimumValue, int maximumValue, byte barColor = 0, byte borderColor = 10, byte indicatorColor = 25);
  1097. Mondo constructor.
  1098.  
  1099.   slider() : gadget() {position = width = height = minimumValue = maximumValue = 0; position = width = height = 0;};
  1100. default constructor.
  1101.  
  1102.   virtual void draw(word offset = VisiblePageOffs);
  1103. draws at current coords.
  1104.  
  1105.   virtual void draw(int x, int y, word offset);
  1106. draws at given coords
  1107.  
  1108.   virtual int activate(void);
  1109. activates slider and sets position.
  1110.  
  1111.   virtual int status(void);
  1112. returns position of slider
  1113. };
  1114.  
  1115. THE GADGETNODE CLASS
  1116. The gadgetNode is an element of a gadgetList, a simple linked-list structure.
  1117.  
  1118. class gadgetNode
  1119. {
  1120. public:
  1121.   gadgetNode * nextGadget;
  1122. next gadget in the list.
  1123.  
  1124.   gadgetNode * prevGadget;
  1125. Previous gadget in the list.
  1126.  
  1127.   gadget * thisGadget;
  1128. The current gadget.
  1129.  
  1130.   gadgetNode(gadget * newGadget, gadgetNode * newNextGadget) {nextGadget = newNextGadget; thisGadget = newGadget, prevGadget = NULL;};
  1131. Constructor.  Note the newNextGadget argument-- replace it with another
  1132. gadgetNode constructor, and several gadgets can be added at once.  See the
  1133. demo program source code for examples.
  1134. };
  1135.  
  1136. THE GADGETLIST CLASS
  1137. A gadgetList consists of several nodes of gadgets, and updates them auto-
  1138. matically.
  1139.  
  1140. class gadgetList
  1141. {
  1142. public:
  1143.   gadgetNode * firstGadget;
  1144. First gadget in the list.
  1145.  
  1146.   gadgetNode * lastGadget;
  1147. Last gadget in the list.
  1148.  
  1149.   virtual int status(void);
  1150. Status of the gadgetList.  Returns the value of whatever button is being
  1151. pressed and also updates all gadgets.
  1152.  
  1153.   gadgetList() {firstGadget = lastGadget = NULL;};
  1154. Constructor.
  1155.  
  1156.   void draw(int x, int y, word offset = VisiblePageOffs);
  1157.   void draw(word offset = VisiblePageOffs);
  1158. Draws all gadgets in the list.
  1159.  
  1160.   void add(gadgetNode * theNewGadget);
  1161. Adds a gadgetNode to the list.
  1162. };
  1163.  
  1164. --------------------------------------------------------------------------
  1165. THE YAKPANEL CLASS
  1166. Bringing together the best worlds-- layered windows and automatic gadgets--
  1167. is the yakPanel class.  It's basically a yakWindow and a gadgetList in one;
  1168. a window full of switches, buttons, or whatever that can be a menu, a control
  1169. panel, or whatever.
  1170.  
  1171. #include "stddefs.h"
  1172. #include "yakwin.h"
  1173. #include "gadgets.h"
  1174.  
  1175. class yakPanel : public yakWindow, public gadgetList //control panel window
  1176. {
  1177. public:
  1178.   yakPanel(int x1, int y1, int x2, int y2) : yakWindow(x1,y1,x2,y2) {myFlags &= ~yakWindow::isSizeable;};
  1179.   virtual word interpretKeyStroke(char myChar);
  1180.   virtual word interpretMouseClick(void);
  1181.   virtual void draw(word offset) {yakWindow::draw(offset); gadgetList::draw(x, y,offset);};
  1182.   virtual int status(void);
  1183. };
  1184.  
  1185. class yakPanel : public yakWindow, public gadgetList //control panel window
  1186. {
  1187. public:
  1188.   yakPanel(int x1, int y1, int x2, int y2) : yakWindow(x1,y1,x2,y2) {myFlags &= ~yakWindow::isSizeable;};
  1189. Default constructor.  Since yakPanels draw themselves by drawing all their
  1190. gadgets, we generally don't want them to be sizeable.
  1191.  
  1192.   virtual word interpretKeyStroke(char myChar);
  1193.   virtual word interpretMouseClick(void);
  1194. YakPanel versions of these functions.
  1195.  
  1196.   virtual void draw(word offset) {yakWindow::draw(offset); gadgetList::draw(x, y,offset);};
  1197.   virtual int status(void);
  1198. ...and these.  Treat it just like a yakWindow OR a yakPanel.  It's that simple.
  1199. See the demo program for easy ways to implement these.
  1200. };
  1201.